home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / iostream.zoo / include / iostream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-22  |  4.5 KB  |  144 lines

  1. //    This is part of the iostream library, providing input/output for C++.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15. //    License along with this library; if not, write to the Free
  16. //    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef _IOSTREAM_H
  19. #pragma interface
  20. #define _IOSTREAM_H
  21. #define Q_ENV
  22.  
  23. #include "streambu.h"
  24.  
  25. class istream; class ostream;
  26. typedef istream& (*__imanip)(istream&);
  27. typedef ostream& (*__omanip)(ostream&);
  28.  
  29. istream& ws(istream& ins);
  30. ostream& flush(ostream& outs);
  31. ostream& endl(ostream& outs);
  32. ostream& ends(ostream& outs);
  33.  
  34. class ostream : public ios
  35. {
  36.     void do_osfx();
  37.   public:
  38.     ostream();
  39.     ostream(streambuf* sb, ostream* tied=NULL);
  40.     ~ostream();
  41.  
  42.     int opfx() { return good(); if (_tie) _tie->flush(); return 1; }
  43.     void osfx() { if (flags() & (ios::unitbuf|ios::stdio))
  44.               do_osfx(); }
  45.     streambuf* ostreambuf() const { return _strbuf; }
  46.     ostream& flush();
  47.     ostream& put(char c);
  48.     ostream& write(const char *s, size_t n);
  49.     ostream& write(const unsigned char *s, size_t n);
  50.     ostream& operator<<(char c);
  51.     ostream& operator<<(unsigned char c) { return *this << (char)c; }
  52.     ostream& operator<<(const char *s);
  53.     ostream& operator<<(const unsigned char *s)
  54.     { return *this << (const char*)s; }
  55.     ostream& operator<<(void *p);
  56.     ostream& operator<<(short n) {return *this << (int)n;}
  57.     ostream& operator<<(int n);
  58.     ostream& operator<<(long n);
  59.     ostream& operator<<(unsigned short n) {return *this << (unsigned int)n;}
  60.     ostream& operator<<(unsigned int n);
  61.     ostream& operator<<(unsigned long n);
  62.     ostream& operator<<(float n);
  63.     ostream& operator<<(double n);
  64.     ostream& operator<<(__omanip func) { return (*func)(*this); }
  65.     ostream& operator<<(streambuf*);
  66.     ostream& form(const char *format ...);
  67.     void close();
  68. };
  69.  
  70. class istream : public ios
  71. {
  72.   public:
  73.     size_t _gcount;
  74.     istream();
  75.     istream(streambuf* sb, ostream*tied=NULL);
  76.     ~istream();
  77.     streambuf* istreambuf() const { return _strbuf; }
  78.     istream& get(char& c);
  79.     istream& get(unsigned char& c);
  80.     int get() { return _strbuf->sbumpc(); }
  81.     istream& getline(char* ptr, int len, char delim = '\n');
  82.     istream& get(char* ptr, int len, char delim = '\n');
  83.     int ipfx(int need) {
  84.     if (!good()) return 0;
  85.     if (_tie && (need == 0 || rdbuf()->in_avail() < need)) _tie->flush();
  86.     if (!need && (flags() & ios::skipws) && !ws(*this)) return 0;
  87.     return 1;
  88.     }
  89.     int ipfx0() { // Optimized version of ipfx(0).
  90.     if (!good()) return 0;
  91.     if (_tie) _tie->flush();
  92.     if ((flags() & ios::skipws) && !ws(*this)) return 0;
  93.     return 1;
  94.     }
  95.     int ipfx1() { // Optimized version of ipfx(1).
  96.     if (!good()) return 0;
  97.     if (_tie && rdbuf()->in_avail() == 0) _tie->flush();
  98.     return 1;
  99.     }
  100.     size_t gcount() { return _gcount; }
  101.     void close();
  102.     int good(); // Make this inline later
  103.     istream& operator>>(char*);
  104.     istream& operator>>(unsigned char* p) { return *this >> (char*)p; }
  105.     istream& operator>>(char& c);
  106.     istream& operator>>(unsigned char& c);
  107.     istream& operator>>(int&);
  108.     istream& operator>>(long&);
  109.     istream& operator>>(short&);
  110.     istream& operator>>(unsigned int&);
  111.     istream& operator>>(unsigned long&);
  112.     istream& operator>>(unsigned short&);
  113.     istream& operator>>(float&);
  114.     istream& operator>>(double&);
  115.     istream& operator>>(__imanip func) { return (*func)(*this); }
  116. };
  117.  
  118. class iostream : public istream, public ostream /*, virtual public ios*/ {
  119.   public:
  120. #if 0
  121.   iostream();
  122.   iostream(FILE *in, FILE *out);
  123.   iostream(FILE *shared);
  124.   ~iostream();
  125. #endif
  126. };
  127.  
  128. extern istream cin;
  129. extern ostream cout, cerr, clog; // clog->rdbuf() == cerr->rdbuf()
  130.  
  131. inline ostream& ostream::put(char c) { _strbuf->sputc(c); return *this; }
  132. inline ostream& ostream::write(const char *s, size_t n)
  133. {
  134.     _strbuf->sputn(s, n);
  135.     return *this;
  136. }
  137. inline ostream& ostream::write(const unsigned char *s, size_t n)
  138. {
  139.     _strbuf->sputn((const char*)s, n);
  140.     return *this;
  141. }
  142.  
  143. #endif /*!_IOSTREAM_H*/
  144.